package com.cdm.beans.license;

import java.util.List;

import net.sf.frails.JSFHelper;
import net.sf.frails.bean.annotations.DefMbean;
import net.sf.frails.bean.annotations.PreRender;
import net.sf.frails.bean.annotations.Prop;

import com.cdm.persistence.ContentUse;
import com.cdm.persistence.EntityManagerHelper;
import com.cdm.persistence.LicensePermission;
import com.cdm.persistence.User;
import com.cdm.util.Constants;

@DefMbean
public class PermissionBean {

	@Prop
	User loginUser;

	@Prop
	List<LicensePermission> permissions;

	@Prop
	List<ContentUse> contentsUse;

	@SuppressWarnings("unchecked")
	@PreRender(failOutcome = "/content/contentInfo")
	public boolean init() {
		Object object = JSFHelper.getFromApplication(Constants.LOGIN_USER_KEY);
		if (object instanceof User && object != null) {
			loginUser = (User) object;
		}

		permissions = EntityManagerHelper.getEntityManager().createQuery("from LicensePermission").getResultList();

		return true;
	}

}
